package strukturaRozpis;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import strukturaSviatky.Sviatky;

public class Sluzba {

    private Calendar datumCas;
    private String kde;
    private int ID_zam1, ID_zam2;
    private String cas;

    public Sluzba(Calendar datumCasSluzby, String popisMiestaTypuSluzby, int ID_zam1New, int ID_zam2New) {
        //popisMiestaTypuSluzby = napriklad F_denna, M_denna, F_nocna...
        datumCas = datumCasSluzby;
        kde = popisMiestaTypuSluzby;
        ID_zam1 = ID_zam1New;
        ID_zam2 = ID_zam2New;
        //ak ID zamestnanca = 0,znamena to ze pozicia nie je obsadena !!!
    }

    public Sluzba(String datumCasSluzby, String kdeNew, int ID_zam1New, int ID_zam2New) throws ParseException {
        final String DATE_FORMAT = "dd.MM.yyyy HH:mm";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        datumCas = new GregorianCalendar();
        datumCas.setTime(sdf.parse(datumCasSluzby));

        kde = kdeNew;
        ID_zam1 = ID_zam1New;
        ID_zam2 = ID_zam2New;
    }

    public void setZam1(int IDzam) {
        ID_zam1 = IDzam;
    }

    public void setZam2(int IDzam) {
        ID_zam2 = IDzam;
    }

    public String getCas() {
        final String DATE_FORMAT = "HH:mm";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return sdf.format(datumCas.getTime());
    }

    public String getDatum() {
        final String DATE_FORMAT = "dd.MM.yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return sdf.format(datumCas.getTime());
    }

    public String getDatumCas() {
        final String DATE_FORMAT = "dd.MM.yyyy HH:mm";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return sdf.format(datumCas.getTime());
    }

    public String getDatumCasSQL() {
        final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return sdf.format(datumCas.getTime());
    }

    public int getDen() {
        final String DATE_FORMAT = "dd";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return Integer.parseInt(sdf.format(datumCas.getTime()));
    }

    public int getMesiac() {
        final String DATE_FORMAT = "MM";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return Integer.parseInt(sdf.format(datumCas.getTime()));
    }

    public int getRok() {
        final String DATE_FORMAT = "yyyy";
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
        return Integer.parseInt(sdf.format(datumCas.getTime()));
    }

    public String getKde() {
        return kde;
    }

    public int getID_zam1() {
        return ID_zam1;
    }

    public int getID_zam2() {
        return ID_zam2;
    }

    public Calendar getCalendar() {
        return datumCas;
    }

    public boolean isSviatok(Sviatky s) {
        for (int i = 0; i < s.getSviatky().size(); i++) {
            if (s.getSviatky().get(i).getDatum().equals(getDatum())) {
                return true;
            }
        }
        return false;
    }

    public boolean isVikend() {
        if (getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || getCalendar().get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            return true;
        }

        return false;
    }

    public boolean isDenna() {
        if (getCas().equals("06:00")) {
            return true;
        }
        return false;
    }

    public boolean isNocna() {
        if (getCas().equals("18:00")) {
            return true;
        }
        return false;
    }
}
